package com.lai.note.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.lai.note.util.CheckNull;

import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * Created by Z先生 on 2019/5/28.
 */

public class LocalDateTimeDeserialize extends JsonDeserializer<LocalDateTime> {
    @Override
    public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        if (jsonParser != null && !CheckNull.isNull(jsonParser.getText())) {
            System.out.println("   传过来的时间为"+jsonParser.getText());
            ZoneOffset zoneOffset = ZoneOffset.of("+8");
            return LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(jsonParser.getText())), zoneOffset);
        } else {
            return null;
        }
    }
}
